function graphs

    % use a MS Office like theme.
    theme(0, 'Office', false,2);
    
    format = 'eps'; %eps
    test = 'MM03';
    branch = 'conditional';
    
    % switch to results directory where all the results.* files should be
    cd 'results';
    mkdir 'graphs';
    
    % result files:
    %output_file = strcat('results.',branch,'_output.',test);
    %collect_file = strcat('results.',branch,'_collect.csv');
    %class_file  = strcat('results.',branch,'_class.',test,'.csv');
    %count_file  = strcat('results.',branch,'_count.',test,'.csv');
    trace_file  = strcat('results.',branch,'_trace.',test,'.csv');
    
    %disp( output_file );
    %disp( collect_file );
    %disp( class_file );
    %disp( count_file );
    %disp( trace_file );
    
    %assert( exist(output_file,'file') ~=0 );
    %assert( exist(collect_file,'file') ~=0 );
    %assert( exist(class_file,'file') ~=0);
    %assert( exist(count_file,'file') ~=0 );
    assert( exist(trace_file,'file') ~=0 );
    
    %cd ..;
    
    fprintf('== %s ==\n',test);
    ligia( trace_file );
    cd ..;
    return;
    
    
    % --------- %
    
    
    plot_output_barsh( collect_file );
    return;
    
    plot_classes( class_file );
    
    %%% 'wrongs' analysis %%%
    analyze_hybrid('gshare','local_limited' ,'gshare_local_h1');
    analyze_hybrid('gshare','local_limited' ,'gshare_local_h2');
    analyze_hybrid('perceptron','local_limited','perceptron_local_h1');
    analyze_hybrid('perceptron','local_limited','perceptron_local_h2');
    
    function analyze_hybrid( c1, c2, hyb )
        save = strcat('graphs/','graphs.',branch,'_wrongs.',test,'.',hyb,'.',format);
        disp(save);
        graph = plot_wrong_cases( class_file , trace_file ,c1,c2,hyb );
        %saveas(graph, save, format);
        %close(graph);
    end
    
    cd ..;
    return;
    %%%%%%%
    
    
    %%% bar graph for output (miss) percentages: %%%
    save = strcat('graphs/','graphs.',branch,'_output.',test,'.',format);
    disp( save );
    graph = plot_output_bars( output_file );
    saveas(graph, save, format);
    close( graph );
    
    %%% plot line with miss percentages progress: %%%
    save = strcat('graphs/','graphs.',branch,'_count.',test,'.',format);
    disp( save );
    graph = plot_count_lines( count_file );
    saveas(graph, save, format);
    close( graph );
    
    %%% bar graph with branch distribution: %%%
    save = strcat('graphs/','graphs.',branch,'_distribution.',test,'.',format);
    disp( save );
    graph = plot_branch_distribution( count_file );
    saveas(graph, save, format);
    close( graph );
    
    %%% pie chart with taken rate and bar chart with frequency distribution %%%
    save = strcat('graphs/','graphs.',branch,'_classes.',test,'.',format);
    disp( save );
    graph = plot_classes( class_file );
    saveas(graph, save, format);
    close( graph );
    
    %%% trace table with hybrid behavior analysis %%%
    output_trace_file = strcat('graphs/','graphs.',branch,'_trace.',test,'.txt');
    disp( output_trace_file );
    output_trace_file = fopen( output_trace_file , 'w' ) ;
    print_hybrid_behavior( output_trace_file, trace_file ,'gshare','local_limited','gshare_local_h1');
    print_hybrid_behavior( output_trace_file, trace_file ,'gshare','local_limited','gshare_local_h2');
    print_hybrid_behavior( output_trace_file, trace_file ,'perceptron','local_limited','perceptron_local_h1');
    print_hybrid_behavior( output_trace_file, trace_file ,'perceptron','local_limited','perceptron_local_h2');
    fclose( output_trace_file );
    
    
    
    % not used, not cleaned...
    %plot_branch_distribution_accum( count_file );
    
    %{
    % gui to ask for result file
    %file = 'results/results.conditional.est';
    %file = 'results/result.trace.conditional.est.csv';
    file = ''; %results/results.conditional_trace.est.csv';
    % set '' for gui...
    
    if( ~exist(file,'file') )
        %cd 'results/';
        [filename, pathname] = uigetfile('*','Select MERGED result CSV file'); %,'MultiSelect','on');
        if isequal(filename,0)
            disp('User Canceled.')
            return;
        else
            disp(['User selected: ', fullfile(pathname, filename)])
            file = fullfile(pathname, filename);
        end
    end
    
    disp(['using file: ',file]);
    
    
    
    if( length( findstr(file, '_output') ) > 0 )
        disp('assuming OUTPUT results file.');
        plot_bars( file );
    end
    
    if( length( findstr(file,'_count') ) > 0 )
        disp('assuming COUNT results file.');
        plot_trace( file );
        %plot_branch_distribution_accum( file );
        plot_branch_distribution( file );
    end
    
    
    if( length( findstr(file,'_class') ) > 0 )
        disp('assuming CLASS results file.');
        plot_classes( file );
    end
    
    if( length( findstr(file,'_trace') ) > 0 )
        disp('assuming TRACE results file.');
        plot_branch_trace( file ,'gshare','local_limited','gshare_local_h1');
        plot_branch_trace( file ,'gshare','local_limited','gshare_local_h2');
        plot_branch_trace( file ,'perceptron','local_limited','perceptron_local_h1');
        plot_branch_trace( file ,'perceptron','local_limited','perceptron_local_h2');
    end
    
    %mkdir('graphs');   
    %}
    
    % return to base directory, once done.
    cd ..;
    
    disp('done');
end

% finds the column index that contains str
function res = getIndex(M,str)
    for i=1:length(M)
        if( strcmp( M(1,i) , str ) )
            res = i;
            return;
        end
    end
    res = -1;
end

function ligia( trace_file )
    data = importdata(trace_file, '\t', 1);
    
    % find indexes:
    real = getIndex(data.textdata,'real');
    c1 = getIndex(data.textdata,'gshare_base');
    
    trace = data.data;
    
    disp( sum(isnan(trace(:,real))) );
    disp( trace(isnan(trace(:,real)),:) );
    
    wrong = xor( trace(:,real) , trace(:,c1) ); % xored
    %disp( wrong );
    %dlmwrite('ligia.txt', wrong,'delimiter', '\t');
    c=0;
    chunks = 0;
    accum = 0;
    total = 0;
    filter_point = 2;
    
    for i=1:length(wrong)
        if( wrong(i,1) == 1 )
            % found possible wrong chunk, start counting
            c = c + 1;
        else
            % now the predictor is correct ( reset c )
            if( c > 0 )
                % if it was bigger than 0, then count this as a new chunk
                chunks = chunks+1;
                
                %%%% hypothetical predictor %%%
                
                if( c >= filter_point ) % invert prediction after more than 1 missed
                    accum = accum + c;
                    total = total+1;
                end
            end
            c = 0;
        end
    end
    
    predictions = length( trace(:,1) );
    wrongs = length( trace( trace(:,real) ~= trace(:,c1) , : ) );
    
    baseline = wrongs;
    optimal = wrongs-accum+(total*filter_point);
    worst = wrongs-accum+total+(total*filter_point);
    
    fprintf('INV. AFTER: %d WRONGS ; AVG. LENGTH: %3.3f\n', filter_point, (accum/total) );
    fprintf('BASE : %3.3f%% \t [ %5d / %d ] \n', baseline/predictions*100 , baseline, predictions );
    % if switches back at the exactly correct time
    fprintf('BEST : %3.3f%% \t [ %5d | %3.3f ] \n', optimal/predictions*100 , (optimal-baseline), (optimal-baseline)/predictions*100  );
    % if switches back after missing one (thus, add total as missed)
    fprintf('WORST: %3.3f%% \t [ %5d | %3.3f ] \n', worst/predictions*100 , (worst-baseline),  (worst-baseline)/predictions*100 );
    
    %disp( predictions );
    %disp( wrongs/predictions );
    %disp( total );
    %disp(accum/total);
end

function graph = plot_wrong_cases( class_file , trace_file , c1_name , c2_name , hyb_name )
    % first line includes labels
    data = importdata(trace_file, '\t', 1);
    
    % find indexes:
    real = getIndex(data.textdata,'real');
    c1 = getIndex(data.textdata,c1_name);
    c2 = getIndex(data.textdata,c2_name);
    hyb = getIndex(data.textdata,hyb_name);
    
    % all indexes must be valid
    assert( real ~= -1 );
    assert( c1 ~= -1 );
    assert( c2 ~= -1 );
    assert( hyb ~= -1 );
    
    trace = data.data;
    
    wrong = trace( trace(:,real) ~= trace(:,hyb) , : );
    wrong_total = length( wrong(:,1) );
    wrong_choice = trace( trace(:,c1) ~= trace(:,c2) & trace(:,real) ~= trace(:,hyb) , : );
    wrong_choice_total = length( wrong_choice(:,1) );

    %disp( wrong_choice_total );
    %disp( wrong_total );
    %disp( wrong_choice_total / wrong_total );
    
    pie_wrong_both = 1 - ( wrong_choice_total / wrong_total );
    pie_wrong_choice = ( wrong_choice_total / wrong_total );
    % pie chart for these
    
    classes = importdata(class_file, '\t', 0);
    
    %total_branches = sum( data(:,2) );
    
    %taken column 4
    zeros = classes( classes(:,4)==0 , : );
    middles = classes( 0<classes(:,4) & classes(:,4)<1 , : );
    ones = classes( classes(:,4)==1 , : );
    
    % class column 1 is branch ID
    % trace column 2 is branch ID
    
    %disp( length( zeros ) );
    %disp( length( middles ) );
    %disp( length( ones ) );
    %disp('-');
    %disp( length( wrong ) );
    %disp( length( wrong( ismember(wrong(:,2),zeros(:,1)) , : ) ) );
    %disp( length( wrong( ismember(wrong(:,2),middles(:,1)) , : ) ) );
    %disp( length( wrong( ismember(wrong(:,2),ones(:,1)) , : ) ) );
    
    %just to shorten the name...
    wrong = wrong_choice;
    
    wrong_nottaken = length( wrong( ismember(wrong(:,2),zeros(:,1)) , : ) );
    wrong_sometimes = length( wrong( ismember(wrong(:,2),middles(:,1)) , : ) );
    wrong_taken =  length( wrong( ismember(wrong(:,2),ones(:,1)) , : ) );
    
    % frequency
    high = classes( 0 < classes(:,6) & classes(:,6) < 1/3 , : );
    moderate = classes( 1/3 <= classes(:,6) & classes(:,6) < 2/3 , : );
    low = classes( 2/3 <= classes(:,6) & classes(:,6) <= 1 , : ); %CLIENT01
    
    %disp('-');
    %disp( length( high ) );
    %disp( length( moderate ) );
    %disp( length( low ) );
    %disp( length( wrong( ismember(wrong(:,2),high(:,1)) , : ) ) );
    %disp( length( wrong( ismember(wrong(:,2),moderate(:,1)) , : ) ) );
    %disp( length( wrong( ismember(wrong(:,2),low(:,1)) , : ) ) );
    
    wrong_high = length( wrong( ismember(wrong(:,2),high(:,1)) , : ) );
    wrong_moderate = length( wrong( ismember(wrong(:,2),moderate(:,1)) , : ) );
    wrong_low = length( wrong( ismember(wrong(:,2),low(:,1)) , : ) );
    
    %assert( wrong_sometimes == wrong_high+wrong_moderate+wrong_low );
    
    graph = figure;
    hold on;
    
    set(gcf, 'Position', get(0,'Screensize'));
    
    subplot( 1 , 2 , 1);
    pie( [pie_wrong_choice pie_wrong_both]);
    
    leg = legend( {'Wrong Choice', 'Wrong Both'} );
    
    set(leg,'Location','Best');
    set(leg,'Interpreter','none');

    % ----
    
    subplot( 1 , 2 , 2 );
    
    values = [ wrong_nottaken wrong_low wrong_moderate wrong_high wrong_taken];
    values = (values / wrong_total) / pie_wrong_choice;
    
    h = pie( values );
    h = findobj(h, 'Type', 'patch');
    meh = hot(100);
    set(h(1),'facecolor',meh(90,:));
    set(h(2),'facecolor',meh(70,:));
    set(h(3),'facecolor',meh(60,:));
    set(h(4),'facecolor',meh(50,:));
    set(h(5),'facecolor',meh(40,:));
    
    leg = legend( {'never', 'low', 'moderate', 'high', 'always'} );
    
    set(leg,'Location','Best');
    set(leg,'Interpreter','none');

    
    %{
    ylabel('number misses');
    xlabel('branch frequency');
    labels = {'never', 'always', 'low', 'moderate', 'high'};
    
    for i = 1:length(values)
        text(i,values(1,i) ,num2str(values(1,i)),'HorizontalAlignment','center','VerticalAlignment','bottom');
    end

    set(gca,'XLim',[ 1-0.5 5+0.5 ]);
    set(gca,'XTick', 1:5);
    set(gca,'XTickLabel',labels);
    %}
        
end

function print_hybrid_behavior( out , file , c1_name , c2_name , hyb_name)
    % first line includes labels
    data = importdata(file, '\t', 1);
    
    % find indexes:
    real = getIndex(data.textdata,'real');
    c1 = getIndex(data.textdata,c1_name);
    c2 = getIndex(data.textdata,c2_name);
    hyb = getIndex(data.textdata,hyb_name);
    
    % all indexes must be valid
    assert( real ~= -1 );
    assert( c1 ~= -1 );
    assert( c2 ~= -1 );
    assert( hyb ~= -1 );
    
    trace = data.data;
    
    % counts total number of decisions/executions (each line is 1)
    total = length( trace(:,1) );
    
    c1_only = trace( ( trace(:,c1) == trace(:,real) ) & ( trace(:,c2) ~= trace(:,real) ), : );
    c1_only = length( c1_only(:,1) );
    
    c2_only = trace( ( trace(:,c2) == trace(:,real) ) & ( trace(:,c1) ~= trace(:,real) ), : );
    c2_only = length( c2_only(:,1) );
    
    c1_and_c2 = trace( ( trace(:,c1) == trace(:,real) ) & ( trace(:,c2) == trace(:,real) ), : );
    c1_and_c2 = length( c1_and_c2(:,1) );
    
    hyb_total = trace( trace(:,hyb) == trace(:,real), : );
    hyb_total = length( hyb_total(:,1) );
    
    choices = trace( trace(:,c1) ~= trace(:,c2) , : );
    choices = length( choices(:,1) );
    
    wrong = trace( trace(:,c1) ~= trace(:,c2) & trace(:,real) ~= trace(:,hyb) , : );
    wrong = length( wrong(:,1) );
    
    assert( wrong <= choices );
    assert( c1_only+c2_only == choices );
    assert( c1_only+c2_only+c1_and_c2 >= hyb_total );
    
    fprintf(out, '\n%s %s %s\n',c1_name , c2_name , hyb_name);
    fprintf(out, 'total & c1_only & c2_only & both & hyb_total & wrong & wrong percent\n');
    fprintf(out, '%d & %d & %d & %d & %d & %d & (%f)\n', total, c1_only, c2_only, c1_and_c2, hyb_total, wrong, (wrong/choices) );
    fprintf(out, 'miss=%f optimal=%f diff=%f\n', 1-hyb_total/total,1-(c1_only+c2_only+c1_and_c2)/total, ((c1_only+c2_only+c1_and_c2)/total - hyb_total/total) );

end

function graph = plot_classes( file )
    data = importdata(file, '\t', 0);
    
    %total_branches = sum( data(:,2) );
    
    %taken column 4
    zeros = data( data(:,4)==0 , : );
    ones = data( data(:,4)==1 , : );
    middles = data( 0<data(:,4) & data(:,4)<1 , : );

    X = [sum( zeros(:,2) )  sum( middles(:,2) )  sum( ones(:,2) )];

    graph = figure;
    hold on;
    
    set(gcf, 'Position', get(0,'Screensize'));
    
    subplot( 1 , 2 , 1);
    pie( X , [0 1 0]);
    
    leg = legend( {'Never' , 'Sometimes' , 'Always'} );
    
    set(leg,'Location','SouthWest');
    set(leg,'Interpreter','none');
    %set(leg,'TextColor',[.3,.2,.1]);

    useful = data( 0<data(:,4) & data(:,4)<1 , : );
    
    step = 0.2;
    %i = 1;
    accum = [];
    labels = [];
    for i=1:5
        from = (i-1)*step;
        to = i*step;
        if( i<1 )
            chunk = useful( from < useful(:,4) & useful(:,4) < to , : );
        else
            %BAH
            chunk = useful( from < useful(:,4) & useful(:,4) <= to , : );
        end
        
        top = chunk( 0 <= chunk(:,6) & chunk(:,6) < 1/3 , : );
        middle = chunk( 1/3 <= chunk(:,6) & chunk(:,6) < 2/3 , : );
        bottom = chunk( 2/3 <= chunk(:,6) & chunk(:,6) <= 1 , : );
        
        %total = length(chunk); %wrong index!
        top = length( top(:,1) );
        middle = length( middle(:,1) );
        bottom = length( bottom(:,1) );
        
        %disp( [top middle bottom] );
        accum = [accum ; [top middle bottom]];
        labels= [labels {strcat( num2str(from*100),'-',num2str(to*100))}];
    end
    subplot( 1 , 2 , 2 );
    
    h = bar( accum, 'stacked' );
    ylabel('number branches');
    xlabel('taken rate');
    
    set(gca,'XLim',[ 1-0.5 5+0.5 ]);
    set(gca,'XTick', 1:5);
    set(gca,'XTickLabel',labels);
    
    meh = hot(100);
    set(h(1),'facecolor',meh(30,:));
    set(h(2),'facecolor',meh(50,:));
    set(h(3),'facecolor',meh(60,:));
    legend(gca,'>66%','33-66%','<33%');
    
end

% bar graph for output miss percentages
function bar_graph = plot_output_barsh( file )
    data = importdata(file, '\t', 1);

    bar_graph = figure;
    hold on;
    
    title('Miss percentage per predictor','FontSize',15);
    ylabel('miss percentage');

    %disp( data.data );
    predictors = data.textdata(1,2:length(data.textdata(1,:)));
    tests = data.textdata(2:length(data.textdata(:,1)),1);

    
    %0.5 because matlab cuts the first and last bard about 50%... WTF?
    set(gca,'XLim',[(1-0.5) (length(tests)+0.5) ]);
    set(gca,'XGrid','off','YGrid','on');
    set(gca,'XTickLabel', tests );
    set(gca,'XTick', 1:length(tests) );
    set(gcf,'Position', get(0,'Screensize'));
    
    
    %file format is (columns): MISSED TOTAL PERCENTAGE
    %values = data.data(:,3);
    bar( data.data , 0.9 );
    
    leg = legend( predictors );
    set(leg,'Location','NorthEastOutside'); %NorthEastOutside
    set(leg,'Interpreter','none');
    
    %disp( values );
    %for i = 1:length(values)
    %    text(i,values(i,1) ,num2str(values(i,1)),'HorizontalAlignment','center','VerticalAlignment','bottom');
    %end
end

% bar graph for output miss percentages
function bar_graph = plot_output_bars( file )
    data = importdata(file, '\t', 0);
    
    bar_graph = figure;
    hold on;
    
    title('Miss percentage per predictor','FontSize',15);
    ylabel('miss percentage');
    
    %0.5 because matlab cuts the first and last bard about 50%... WTF?
    set(gca,'XLim',[(1-0.5) (length(data.data)+0.5) ]);
    set(gca,'XGrid','off','YGrid','on');
    set(gca,'XTickLabel', data.textdata );
    set(gca,'XTick', 1:length(data.data) );
    set(gcf, 'Position', get(0,'Screensize'));
    
    %file format is (columns): MISSED TOTAL PERCENTAGE
    values = data.data(:,3);
    bar( values , 0.9 );
    %disp( values );
    for i = 1:length(values)
        text(i,values(i,1) ,num2str(values(i,1)),'HorizontalAlignment','center','VerticalAlignment','bottom');
    end
end

function graph = plot_branch_distribution( file )
    data = importdata(file, '\t', 1);
    
    %disp( data.textdata );
    %disp( data.data(:,6) );
    
    dist = data.data(:,5);
    classes = 10; %how many classes?
    step = round(length(dist)/classes);
    labels = [];
    
    for i=1:classes
       min = (1+(i-1)*step);
       max = (i*step);
       if( max > length( dist ) )
           max = length( dist );
       end
       res(i) = sum( dist( min : max ));
       %disp( strcat( num2str(min),'-',num2str(max) ) );
       labels= [labels {strcat( num2str(min),'-',num2str(max))}];
    end
    
    %disp( length( dist) );
    %disp( length( res ) );
    
    %plot stuff
    
    graph = figure;
    hold on;

    set(gca, 'Box', 'on');
    set(gcf, 'Position', get(0,'Screensize'));
    set(gca,'XGrid','off','YGrid','on');
    
    title('Branch Distribution','FontSize',15);
    xlabel('Times Executed'); % (step=',num2str(step),')']);
    ylabel('Number Branches');
    
    set(gca,'XLim',[ 1-0.5 10+0.5 ]);
    set(gca,'XTick',[1:classes])
    set(gca,'XTickLabel',labels);
    bar( res/sum( dist ) , 1 );
    
    %disp( sum( res/sum(dist) ) );
    %plot( data.data(:,4) );
    
end

function graph = plot_branch_distribution_accum( file )
    data = importdata(file, '\t', 1);
    
    graph = figure;
    hold on;
    
    set(gca, 'Box', 'on');
    set(gcf, 'Position', get(0,'Screensize'));
    set(gca,'XGrid','off','YGrid','on');
    
    title('Branch Distribution Accum','FontSize',15);
    xlabel('Times Executed');
    ylabel('Number Branches');
    
    % accumulated values
    plot( data.data(:,4) );
    % unique values
    %plot( data.data(:,5) );
    
end

% plots a trace of miss predictions per number of branch executions
function graph = plot_count_lines( file )
    % note that first line includes labels
    data = importdata(file, '\t', 1);
    
    graph = figure;
    hold on;

    set(gca, 'Box', 'on');
    set(gcf, 'Position', get(0,'Screensize'));
    set(gca, 'XGrid','off','YGrid','on');
    
    xlabel('number executions (per branch)');
    ylabel('percentage missed');
    
    labels = data.textdata(:,2:4:length(data.textdata(1,:)));
    values = data.data(:,2:4:length(data.data(1,:)));
    
    % trims first 100 values
    values = values(1:100,:);
    %shifts graph starting point to '1'
    set(gca,'XLim',[ 1 100 ]);
    
    %using theme colors
    plot( values );
    
    % manually chosen colors:
    %colors = hsv( length(labels) );
    %for i=1:length(labels)
    %    plot( values(:,i) , 'color', colors(i,:) );
    %end
    
    leg = legend( labels );
    set(leg,'Location','NorthEast'); %NorthEastOutside
    set(leg,'Interpreter','none');
end


% OLD VERSION FOR REFERENCE DO NOT DELETE
%{
function load_data(file)
    data = importdata(file, '\t', 1);
    
    X = size(data.data, 2);
    Y = size(data.data, 1); 
    
    for i = 1:X;
        varName = char(data.textdata(i));
        varName = strrep(varName, '-', '_');
        
        varValue = data.data(1:Y, i);
        
        assignin('caller', varName, varValue);
    end
end

function plot_graph1(gshare_total)
    graph1 = figure;
    
    hold on;        
    %set(gca, 'XTickLabel', '');
    %set(gca, 'YTickLabel', '');
    set(gca, 'Box', 'on');
    set(gcf, 'Position', get(0,'Screensize'));
    set(gca,'XGrid','on','YGrid','on');
    
    title('Branch Distribution','FontSize',15);
    xlabel('Times Executed');
    ylabel('Number Branches');
    
    plot(gshare_total);
    
    %leg = legend('gshare_total');
    %set(leg,'Location','NorthEastOutside');
    %set(leg,'Interpreter','none');
    %set(leg,'FontAngle','TextColor',[.3,.2,.1]);
    
    %axis tight;
    
    %saveas(graph1, 'graphs/graph1', 'eps');
    %saveas(graph1, 'graphs/graph1', 'pdf');
end

function plot_graph2(gshare_perc, ISL_TAGE_cond_perc, ITTAGE_ind_perc, ...
        last_perc, nottaken_perc, ogehl_perc, perceptron_perc, ...
        piecewise_perc, random_perc, taken_perc)
    
    graph2 = figure;
    
    hold on;
    
    %set(gca, 'XTickLabel', '');
    %set(gca, 'YTickLabel', '');
    set(gca, 'Box', 'on');
    set(gcf, 'Position', get(0,'Screensize'));
    set(gca,'XGrid','off','YGrid','on');
    
    xlabel('number execution (per branch)');
    ylabel('percentage missed');
    
    colors = hsv(10);
    
    plot(gshare_perc, 'color', colors(1, :));
    plot(ISL_TAGE_cond_perc, 'color', colors(2, :));
    plot(ITTAGE_ind_perc, 'color', colors(3, :));
    plot(last_perc, 'color', colors(4, :));
    plot(nottaken_perc, 'color', colors(5, :));
    plot(ogehl_perc, 'color', colors(6, :));
    plot(perceptron_perc, 'color', colors(7, :));
    plot(piecewise_perc, 'color', colors(8, :));
    plot(random_perc, 'color', colors(9, :));
    plot(taken_perc, 'color', colors(10, :));
    
    leg = legend('gshare_perc', ...
                 'ISL_TAGE_cond_perc', ...
                 'ITTAGE_ind_perc', ...
                 'last_perc', ...
                 'nottaken_perc', ...
                 'ogehl_perc', ...
                 'perceptron_perc', ...
                 'piecewise_perc', ...
                 'random_perc', ...
                 'taken_perc');
    set(leg,'Location','NorthEastOutside');
    set(leg,'Interpreter','none');
    set(leg,'TextColor',[.3,.2,.1]);
    %set(leg,'FontAngle','italic','TextColor',[.3,.2,.1]);

    %axis tight;
    
    %saveas(graph2, 'graphs/graph2', 'eps');
    %saveas(graph2, 'graphs/graph2', 'pdf');    
end
%}
